package org.zfes.snowier.zbss.xzy.biz.zmd.service.impl;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import org.zfes.snowier.core.data.DataSet;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.zfes.snowier.core.util.ZBeanUtil;
import org.zfes.snowier.core.util.ZDateUtil;
import org.zfes.snowier.core.util.ZStrUtil;
import org.zfes.snowier.core.util.ZAlert;
import org.zfes.snowier.core.util.ZAssert;
import org.zfes.snowier.core.data.ParamMap;
import com.google.common.collect.Lists;
import org.zfes.snowier.core.data.SelectVo;

import org.zfes.snowier.zbss.xzy.biz.zmd.service.IModataSysService;
import org.zfes.snowier.zbss.xzy.biz.zmd.dao.ModataSysMapper;
import org.zfes.snowier.zbss.xzy.biz.zmd.model.ModataSys;
import java.util.stream.Stream;
@Service
public class ModataSysServiceImpl implements IModataSysService{
 	@Autowired
	private ModataSysMapper modataSysMapper;
	
	@Transactional(rollbackFor=Exception.class)
 	@Override
	public void createModataSys(ModataSys modataSys) {
		ZBeanUtil.setCreateInfo(modataSys);
		ZBeanUtil.validateBean(modataSys);
		modataSysMapper.insertSelective(modataSys);
	}
	@Transactional(rollbackFor=Exception.class,readOnly=true)
	@Override
	public Optional<ModataSys> loadModataSysById(Long id) {
		if(id!=null){
			return Optional.ofNullable(modataSysMapper.selectByPrimaryKey(id));
		}
		return Optional.empty();
		
	}
	@Transactional(rollbackFor=Exception.class)
	@Override
	public void updateModataSys(ModataSys modataSys) {
		ZBeanUtil.setUpdatedInfo(modataSys);
		ZBeanUtil.validateBean(modataSys);
		modataSysMapper.updateByPrimaryKeySelective(modataSys);
	}
	
	@Transactional(rollbackFor=Exception.class)
	@Override
	public void deleteModataSys(Long id) {
		ZAssert.notNull(id, "请选择要操作的数据");
		modataSysMapper.deleteByPrimaryKey(id);
	}
	@Transactional(rollbackFor=Exception.class)
	@Override
	public void setModataSysStatus(Long id, Byte status) {
		ZAssert.notNull(id, "请选择要操作的数据");
		ZAssert.notNull(status, "状态参数错误");
		if(!Stream.of(new Byte[] {-1,0,1}).anyMatch(val->val.equals(status))) {
			ZAlert.serviceLogicalError("状态参数错误");
		}
		modataSysMapper.updateStatus( id,  status) ;
	}
	@Transactional(rollbackFor=Exception.class,readOnly=true)
	@Override
	public DataSet loadModataSysDataSet(Map<String, Object> params) {
		ParamMap pm=ParamMap.filterParam(params);
		DataSet ds=DataSet.newDS2(modataSysMapper.selectListCount(pm), modataSysMapper.selectMapListPage(pm));
		return ds;
	}
	
	
	@Transactional(rollbackFor=Exception.class,readOnly=true)
	@Override
	public List<SelectVo> loadModataSysSelectVo(String keywords) {
		if(ZStrUtil.hasText(keywords)) {
			
		}
		List<SelectVo> voList=modataSysMapper.selectDropList(Byte.valueOf("1"));
		
		return voList==null?Lists.newArrayList():voList;
	}
    
}